package com.fr.chart;

import com.fr.base.XMLable;
import com.fr.base.core.GraphHelper;
import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.axis.SeriesAttrAlpha;
import com.fr.chart.axis.SeriesAttrLine;
import com.fr.chart.base.equals.Equals;
import com.fr.chart.core.ChartCoreConstants;
import com.fr.chart.core.ChartUtils;
import com.fr.chart.plot.SeriesCollection;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.Shape;

public class LineStyleInfo
  implements XMLable, GlyphCondition
{
  private static final long serialVersionUID = -5616374725367075547L;
  public static final String XML_TAG = "LineStyleInfo";
  private SeriesAttrLine seriesAttrLine = new SeriesAttrLine();
  private SeriesAttrAlpha seriesAttrAlpha = new SeriesAttrAlpha();

  public LineStyleInfo()
  {
  }

  public LineStyleInfo(int paramInt)
  {
    this.seriesAttrLine.setSeriesLineColor((Color)ChartUtils.getObject(paramInt, ChartCoreConstants.CHART_COLOR_ARRAY));
  }

  public void setDefaultAlpha(float paramFloat)
  {
    getSeriesAttrAlpha().setAlpha(paramFloat);
  }

  public float getDefaultAlpha()
  {
    return getSeriesAttrAlpha().getAlpha();
  }

  public void setSeriesAttrAlpha(SeriesAttrAlpha paramSeriesAttrAlpha)
  {
    this.seriesAttrAlpha = paramSeriesAttrAlpha;
  }

  public SeriesAttrAlpha getSeriesAttrAlpha()
  {
    return this.seriesAttrAlpha;
  }

  public void setSeriesLineColor(Color paramColor)
  {
    this.seriesAttrLine.setSeriesLineColor(paramColor);
  }

  public Color getSeriesLineColor()
  {
    return this.seriesAttrLine.getSeriesLineColor();
  }

  public void setSeriesLineStyle(int paramInt)
  {
    this.seriesAttrLine.setSeriesLineStyle(paramInt);
  }

  public int getSeriesLineStyle()
  {
    return this.seriesAttrLine.getSeriesLineStyle();
  }

  public void setSeriesAttrLine(SeriesAttrLine paramSeriesAttrLine)
  {
    this.seriesAttrLine = paramSeriesAttrLine;
  }

  public SeriesAttrLine getSeriesAttrLine()
  {
    return this.seriesAttrLine;
  }

  public void paint(Graphics paramGraphics, Shape paramShape)
  {
    if ((paramShape == null) || (getSeriesLineColor() == null) || (getSeriesLineStyle() == 0))
      return;
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    Paint localPaint = localGraphics2D.getPaint();
    Composite localComposite = localGraphics2D.getComposite();
    localGraphics2D.setPaint(getSeriesLineColor());
    localGraphics2D.setComposite(AlphaComposite.getInstance(3, getDefaultAlpha()));
    GraphHelper.draw(localGraphics2D, paramShape, getSeriesLineStyle());
    localGraphics2D.setPaint(localPaint);
    localGraphics2D.setComposite(localComposite);
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isChildNode())
    {
      String str1 = paramXMLableReader.getTagName();
      if (str1.equals("Attr"))
      {
        String str2;
        if ((str2 = paramXMLableReader.getAttr("alpha")) != null)
          setDefaultAlpha(Float.parseFloat(str2));
        if ((str2 = paramXMLableReader.getAttr("lineStyle")) != null)
          setSeriesLineStyle(Integer.parseInt(str2));
        if ((str2 = paramXMLableReader.getAttr("lineColor")) != null)
          setSeriesLineColor(new Color(Integer.parseInt(str2), true));
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("LineStyleInfo");
    paramXMLPrintWriter.startTAG("Attr").attr("alpha", getDefaultAlpha()).attr("lineStyle", getSeriesLineStyle());
    if (getSeriesLineColor() != null)
      paramXMLPrintWriter.attr("lineColor", getSeriesLineColor().getRGB());
    paramXMLPrintWriter.end();
    paramXMLPrintWriter.end();
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    LineStyleInfo localLineStyleInfo = (LineStyleInfo)super.clone();
    return localLineStyleInfo;
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof LineStyleInfo))
      return false;
    LineStyleInfo localLineStyleInfo = (LineStyleInfo)paramObject;
    if (localLineStyleInfo.getDefaultAlpha() != getDefaultAlpha())
      return false;
    if (localLineStyleInfo.getSeriesLineStyle() != getSeriesLineStyle())
      return false;
    return (Equals.equals(localLineStyleInfo.getSeriesLineColor(), getSeriesLineColor()));
  }

  public void dealCondition(SeriesCollection paramSeriesCollection, int paramInt)
  {
    SeriesAttrLine localSeriesAttrLine = (SeriesAttrLine)paramSeriesCollection.getSeriesCondition(new SeriesAttrLine(), paramInt);
    setSeriesAttrLine(localSeriesAttrLine);
    SeriesAttrAlpha localSeriesAttrAlpha = (SeriesAttrAlpha)paramSeriesCollection.getSeriesCondition(new SeriesAttrAlpha(), paramInt);
    setSeriesAttrAlpha(localSeriesAttrAlpha);
  }

  public JSONObject toJSONObject()
    throws JSONException
  {
    JSONObject localJSONObject = new JSONObject();
    if (this.seriesAttrAlpha != null)
      localJSONObject.put("seriesAttrAlpha", this.seriesAttrAlpha.toJSONObject());
    if (this.seriesAttrLine != null)
      localJSONObject.put("seriesAttrLine", this.seriesAttrLine.toJSONObject());
    return localJSONObject;
  }
}